package ui;

import data.BankDatabase;

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

/** Represents the ui for deleting a user
 * @author Matthias
 * @author NielsChristianMouritsen
 *
 */
public class AdmDelete extends JPanel{
	
	private JButton btn_Submit;
	private JLabel lbl_User;
	private JComboBox<String> comboBox_Delete;
	private JButton btn_Back;
	private JLabel lbl_Header;
	private JLabel logo_ATM;
	
	/** Declaring the BankDatabase object by the type bdb **/
	private BankDatabase bdb;
	/** Declaring the Screen object by the type screen **/
	private Screen screen;
	
	/** Contains the information/blueprint on labels, buttons and combo boxes
	 * Sets the window Dimensions
	 * @param screen
	 */
	public AdmDelete(Screen screen) {

		this.screen = screen;
		this.bdb = screen.getClassATM().getClassBankDatabase();
		
		setPreferredSize(new Dimension(600, 480));
		setLayout(null);
		
		btn_Submit = new JButton("Submit");
		btn_Submit.setFont(new Font("SansSerif", Font.PLAIN, 16));
		btn_Submit.setBounds(400, 360, 130, 50);
		add(btn_Submit);
		
		lbl_User = new JLabel("Which user do you want to delete?");
		lbl_User.setFont(new Font("SansSerif", Font.BOLD, 16));
		lbl_User.setBounds(147, 125, 263, 21);
		add(lbl_User);

		comboBox_Delete = new JComboBox<String>();
		comboBox_Delete.setFont(new Font("SansSerif", Font.PLAIN, 16));
		comboBox_Delete.setBounds(147, 170, 263, 53);
		addAllUsers();
		add(comboBox_Delete);
		
		btn_Back = new JButton("Back");
		btn_Back.setFont(new Font("SansSerif", Font.PLAIN, 16));
		btn_Back.setBounds(60, 360, 130, 50);
		add(btn_Back);
		
		lbl_Header = new JLabel("Delete User");
		lbl_Header.setFont(new Font("SansSerif", Font.BOLD, 26));
		lbl_Header.setBounds(200, 40, 142, 34);
		add(lbl_Header);

		logo_ATM = new JLabel("");
		logo_ATM.setIcon(new ImageIcon(AdmDelete.class.getResource("/pic/LOGO Mini.png")));
		logo_ATM.setBounds(15, 15, 50, 50);
		add(logo_ATM);
	}
	
	/** Adds action listeners
	 * @param e
	 */
	public void addActionListener(ActionListener e){
		comboBox_Delete.addActionListener(e);
		btn_Back.addActionListener(e);
		btn_Submit.addActionListener(e);
	}
	
	/**
	 * @return submit button
	 */
	public JButton getSubmit() {
		return btn_Submit;
	}
	
	/**
	 * @return back button
	 */
	public JButton getBack() {
		return btn_Back;
	}
	
	/**
	 * @return the combo box
	 */
	public JComboBox<String> getComboBox() {
		return comboBox_Delete;
	}
	
	/** 
	 * Adding all existing users to the comboBox.
	 */
	public void addAllUsers(){
		comboBox_Delete.removeAllItems();	
		String account[] = bdb.getUserChanger();
		for(int i = 0; i < account.length;i++){
			comboBox_Delete.addItem(account[i]);		
		}
		screen.pack();
	}
	
	/** Used to delete a specific user ID 
	 * @return the user Id of the selected item in the combobox
	 */
	public int getSpecificUserID(){
		int[] info = new int[bdb.getUserList().size()];
	    for (int i = 0; i < bdb.getUserList().size(); i++) {
			info[i] = bdb.getUserList().get(i).getUserID();
		}
	    return info[comboBox_Delete.getSelectedIndex()];
	}

} // end class AdmDelete